#ifndef _S_CSAM_DRIVER_H_
#define _S_CSAM_DRIVER_H_

#define S_CSAM_DRIVER_05FILE_TERMINALID_TYPE            	0x00
#define S_CSAM_DRIVER_05FILE_PASSCODEID_TYPE            	0x01

#define S_CSAM_DRIVER_08FILE_SERVERCCKSID_TYPE				0x02
#define S_CSAM_DRIVER_08FILE_LKEY_TYPE                      0x03
#define S_CSAM_DRIVER_08FILE_PASSKEYPRIVILEGEDTIME_TYPE     0x04
#define S_CSAM_DRIVER_08FILE_PASSKEYEFFECTIVELIFE_TYPE      0x05

#define S_CSAM_DRIVER_05FILE_TERMINALID_SIZE                0x06
#define S_CSAM_DRIVER_05FILE_PASSCODEID_SIZE                0x0A

#define S_CSAM_DRIVER_08FILE_SERVERCCKSID_MAXSIZE			48
#define S_CSAM_DRIVER_08FILE_LKEY_SIZE                      0x20
#define S_CSAM_DRIVER_08FILE_PASSKEYPRIVILEGEDTIME_SIZE     0x04
#define S_CSAM_DRIVER_08FILE_PASSKEYEFFECTIVELIFE_SIZE      0x04


#define S_CSAM_DRIVER_09FILE_SERVERCCKSID_MAXSIZE			48
#define S_CSAM_DRIVER_09FILE_LOCKID_SIZE					6
#define S_CSAM_DRIVER_09FILE_KEYTYPE_SIZE					1
#define S_CSAM_DRIVER_09FILE_LOCKBLEMAC_SIZE				6
#define S_CSAM_DRIVER_09FILE_UTCTIME_SIZE					4
#define S_CSAM_DRIVER_09FILE_TIMEZONEMSG_SIZE				21
#define S_CSAM_DRIVER_09FILE_SERVERSIGNEDDATA_SIZE			30

#define S_CSAM_DRIVER_RANDOMDATA_LEN                		10

typedef enum
{
	csam_init_success = 0,
	csam_init_failed,
	csam_init_terminalID_failed
}s_csam_driver_init_rslt;

typedef struct
{
	unsigned char serverCCKSID_len;
	unsigned char *serverCCKSID;
	unsigned char lockID[S_CSAM_DRIVER_09FILE_LOCKID_SIZE];
	unsigned char keytype;
	unsigned char lockBLEMAC[S_CSAM_DRIVER_09FILE_LOCKBLEMAC_SIZE];
	unsigned char starttime[S_CSAM_DRIVER_09FILE_UTCTIME_SIZE];
	unsigned char endtime[S_CSAM_DRIVER_09FILE_UTCTIME_SIZE];
	unsigned char timezone_msg[S_CSAM_DRIVER_09FILE_TIMEZONEMSG_SIZE];
	unsigned char serverSignedData[S_CSAM_DRIVER_09FILE_SERVERSIGNEDDATA_SIZE];
	unsigned char terminalID[S_CSAM_DRIVER_05FILE_TERMINALID_SIZE];
}s_csam_driver_09file_t, *p_s_csam_driver_09file_t;


extern s_csam_driver_init_rslt s_csam_driver_init_rslt_flag;

extern void S_CSAM_Driver_Test(void);
extern signed char S_CSAM_Driver_Init(void);
extern void S_CSAM_Driver_ColdReset(void);

extern signed char S_CSAM_Driver_GetRandomNums(unsigned char *random);
extern signed char S_CSAM_Driver_CheckSign(unsigned char *signdata, \
							unsigned char *rsp);
extern signed char S_CSAM_Driver_GetSign(unsigned char *data2sign, \
									unsigned short datalength, \
									unsigned char *datasigned, \
									unsigned char *rsp);

extern signed char S_CSAM_Driver_Get05FilePara(unsigned char *data, \
											unsigned char type);
extern signed char S_CSAM_Driver_Get08FilePara(unsigned char *data, \
											unsigned char type);
extern p_s_csam_driver_09file_t S_CSAM_Driver_Get09File_StructPoint(void);
extern void S_CSAM_Driver_Get09File_StructPoint_Release(p_s_csam_driver_09file_t *p_data_09file_t);

extern void s_csam_driver_vcc_high(void);
extern void s_csam_driver_vcc_low(void);

extern void s_csam_driver_halt(void);
extern void s_csam_driver_active(void);
#endif
